#pragma once

#include <QMainWindow>
#include <QSettings>
#include <QListWidgetItem>
#include <QMenu>
#include <QLocalServer>
#include <QSplashScreen>
#include <QTreeWidgetItem>
#include "iconcache.h"
#include "imageview.h"
#include "piocoreimpl.h"
#include "scanner.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QSplashScreen * splash, QWidget *parent = 0);
    ~MainWindow();
    QToolBar * toolbar();

public slots:
    void setStatus(const QString & str);
    void addOverlay(QWidget * overlay);
    void removeOverlay(QWidget * overlay);
    void addToolWidget(QWidget * widget, QString title);
    void removeToolWidget(QWidget * widget);
    void selectToolWidget(QWidget * widget);

private slots:
    void on_actionEdit_triggered();
    void on_actionDelete_triggered();
    void on_collectionsList_itemDoubleClicked(QListWidgetItem* item);
    void on_checkNoCollectionsButton_pressed();
    void on_checkAllCollectionsButton_pressed();
    void on_addCollection_pressed();
    void setFullscreen(bool);
    void selectCollections();
    void onItemsDroppedOnCollection(const QList<QUrl> & urls, QListWidgetItem * item);
    void onContextMenuRequested();
    void onView(MediaItemPtr item);

    void onSelectionChanged(QList<MediaItemPtr> selection);
    void onCloseView();
    void on_resetCollectionSelection_pressed();
    void on_actionSave_collection_selection_triggered();
    void onNewConnection();
    void on_actionRawAndProcessed_triggered();
    void on_actionRawOnly_triggered();
    void on_actionProcessedOnly_triggered();
    void on_actionDevelop_triggered();
    void import(ImportModule * module, QList<int> selection, bool deleteSource, bool ejectMedium);
    void on_actionUnprocessedRaw_triggered();
    void on_actionSlideShow_triggered();
    void onSlideShowTimer();
    void on_actionNoDevelopedRaw_triggered();
    void on_actionUpdateLibrary_triggered();
    void on_actionAbout_triggered();
    void onCollectionsListContextMenuRequested(QPoint p);
    void on_actionFullscreen_triggered();
    void on_actionCheck_triggered();
    void on_actionSelectCheckedFiles_triggered();
    void on_actionUncheckAll_triggered();
    void onKeywordsChanged();
    void onCollectionsChanged();

private:
    void loadPlugins();
    void processArguments(QStringList args);
    QTreeWidgetItem * addKeyword(const QString & str, QTreeWidgetItem * parent = NULL);
    //void synchronize(const QList<QSharedPointer<Keyword> > & keywords, const QSharedPointer<Keyword> & parent_keyword, class QTreeWidgetItem * parent_item);

    Ui::MainWindow *ui;

    QLocalServer m_singleinstance;

    PioCoreImpl m_core;
    QMenu m_contextMenu;
    QMenu m_collectionsContextMenu;
    bool m_menubarVisible, m_toolbarVisible, m_sidebarVisible, m_statusbarVisible, m_maximized;
    QList<MediaItemPtr> m_slideShow;
    QTimer m_slideShowTimer;
    QList<class PioPlugin*> m_plugins;
    Scanner m_scanner;
};
